﻿// (c) Copyright slimCODE Software Inc. - www.slimcode.com
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.

using System;

using System.Collections.Generic;
using System.Text;
using SlimCode.Windows.Controls.Mobile;
using System.Drawing;

namespace SlimCode.SlimPasswords
{
  internal class BooleanOptionView : ItemView
  {
    private Image m_falseImage;
    private Image m_trueImage;

    public BooleanOptionView( Image falseImage, Image trueImage, string text, bool value )
      : base( falseImage, ContentAlignmentEx.MiddleLeft, text, ContentAlignmentEx.MiddleLeft, 2 )
    {
      m_falseImage = falseImage;
      m_trueImage = trueImage;

      this.Value = value;
    }

    #region Value PROPERTY

    private bool m_value;

    public bool Value
    {
      get { return m_value; }
      set
      {
        if( m_value != value )
        {
          m_value = value;
          this.OnValueChanged();
        }
      }
    }

    protected virtual void OnValueChanged()
    {
      this.Image = ( m_value ? m_trueImage : m_falseImage );
    }

    #endregion

    protected override Size GetPreferredSize( TemplatedPaintEventArgs args, Rectangle workingRect, System.Windows.Forms.Orientation orientation )
    {
      try
      {
        return base.GetPreferredSize( args, workingRect, orientation );
      }
      finally
      {
        if( this.MaxImageSize.IsEmpty )
        {
          this.MaxImageSize = new Size( this.LineHeight, this.LineHeight );
        }
      }
    }
  }
}
